package _29define;

import java.lang.reflect.Field;

public class Work1 {
    public static void main(String[] args) throws Exception {
        AAA aaa = new AAA();
        setAll( aaa,"name","李四");
        System.out.println(aaa.name);
    }
    public static void setAll(Object targetObj,String fieldName,Object newValue) throws Exception{
        Class<?> c=targetObj.getClass();
        Field field=c.getDeclaredField(fieldName);
        field.set(targetObj,newValue);
    }
}
class AAA{
    String name="张三";
}